package test;

import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

public class App {
	
	public static void main(String[] args) {
		for(int i=0;i<10;i++) {
			try {
				DemoThread thread = new DemoThread(new Random().nextInt(10), "thread ["+i+"]");
				thread.start();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		while(true) {
			int j = DemoThread.i.intValue();
			if(j==10) {
				System.out.println("hello world!!");
				break;
			}
		}
	}
	
}

class DemoThread extends Thread {
	
	private int time;
	private String name;
	public static AtomicInteger i = new AtomicInteger(0);
	
	public DemoThread(int time, String name) {
		this.time = time;
		this.name = name;
	}
	
	@Override
	public void run() {
		try {
			Thread.sleep(time*1000);
			System.out.println("I'm thread["+name+"]");
			i.incrementAndGet();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
}
